import api from "./index";
import request from "../utils/request";

export function createSurvey(id,title,introduction,maxAnswers,startTime,endTime,question){
  const data = {
    userId:id,
    title:title,
    introduction:introduction,
    maxAnswers:maxAnswers,
    startTime:startTime,
    endTime:endTime,
    questionArray:question,
  }
  return request({
    url: api.createSurvey,
    method: "post",
    data
  })
}

export function editSurvey(userId,surveyId,title,introduction,maxAnswers,startTime,endTime,question){
  const data = {
    userId:userId,
    surveyId:surveyId,
    title:title,
    introduction:introduction,
    maxAnswers:maxAnswers,
    startTime:startTime,
    endTime:endTime,
    questionArray:question,
  }
  return request({
    url: api.editSurvey,
    method: "post",
    data
  })
}

export function querySurveyList(userId,key){
  const data = {
    userId:userId,
    title:key,
  }
  return request({
    url: api.querySurveyList,
    method: "post",
    data
  })
}

export function deleteSurvey(id){
  const data = {id:id}
  return request({
    url: api.deleteSurvey,
    method: "post",
    data
  })
}

export function getSurveyDetail(id){
  const data = {id:id}
  return request({
    url: api.getSurveyDetail,
    method: "post",
    data
  })
}

export function deliverToGroups(surveyId,groupsIds){
  const data = {
    surveyId : surveyId,
    groupIds : groupsIds
  }
  return request({
    url: api.deliverToGroups,
    method: "post",
    data
  })
}

export function deliverToAnswerers(surveyId,answererIds){
  const data = {
    surveyId : surveyId,
    answererIds : answererIds
  }
  return request({
    url: api.deliverToAnswerers,
    method: "post",
    data
  })
}

export function showSurvey(id){
  const data = {id:id}
  return request({
    url:api.showSurvey,
    method:'post',
    data
  })
}
export function answerSurvey(answererId,surveyId,answers){
  const data = {
    answererId:answererId,
    surveyId:surveyId,
    answers:answers
  }
  return request({
    url:api.answerSurvey,
    method:'post',
    data
  })
}
export function showAnswerSurvey(answererId,surveyId){
  const data = {
    answererId:answererId,
    surveyId:surveyId
  }
  return request({
    url:api.showAnswerSurvey,
    method:'post',
    data
  })

}

export function getAnswerInfo(surveyId){
  const data = {surveyId:surveyId}
  return request({
    url: api.getAnswerInfo,
    method: "post",
    data
  })
}

export function getSurveyContext(surveyId, answererId){
  const data = {
    surveyId: surveyId,
    answererId: answererId
  }
  return request({
    url: api.getSurveyContext,
    method: "post",
    data
  })
}
